<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\Post\RouteAction;
use App\Http\Controllers\Controller;
use App\Models\ShopSellRank;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;

class ShopRankController extends Controller {
	use HasResourceActions;

	/**
	 * Index interface.
	 *
	 * @param Content $content
	 * @return Content
	 */
	public function index(Content $content) {
		return $content
			->header('店铺销售排名')
			->description('店铺每个价格段销售排行榜')
			->body($this->grid());
	}

	/**
	 * Make a grid builder.
	 *
	 * @return Grid
	 */
	protected function grid() {
		$grid = new Grid(new ShopSellRank);
		$grid->disableExport();
		$grid->disableCreateButton();
		$grid->actions(function ($actions) {

			$actions->disableDelete();
			$actions->disableEdit();
			$actions->disableView();
			$actions->add(new RouteAction(1));
		});
		$grid->id('ID');
		$grid->shop_id('店铺ID')->display(function ($shop_id) {
			return "<a target='_blank'  href='http://shop.kongfz.com/" . $shop_id . "'>" . $shop_id . "</a>";
		});
		$grid->shop()->shopname('店铺名');
		$grid->price_range('价格段')->sortable();
		$grid->sell_number('销售数量')->sortable();
		$grid->filter(function ($filter) {
			$filter->disableIdFilter();
			$filter->equal('shop_id', '店铺ID')->integer();
			$filter->equal('price_range', '价格段');

		});
		return $grid;
	}

	public function show($id) {
		$shop_id = ShopSellRank::find($id)->shop_id;
		return redirect(route('goods.index') . "?shop_id=" . $shop_id);

	}

}
